package com.hxkj.controller;


import com.github.pagehelper.PageInfo;
import com.hxkj.domain.po.DictItem;
import com.hxkj.service.DictItemService;
import com.platform.common.domain.to.PageTo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


/**
 * 二级字典列表 服务层
 * <p>
 * Created by zzx on 2018/5/15.
 */
@RestController
@RequestMapping("/dictItem")
public class DictItemController {


    @Autowired
    private DictItemService dictItemService;

    @RequestMapping(value = "/getlist", method = RequestMethod.POST)
    public PageInfo getList(@ModelAttribute DictItem dictItem, @ModelAttribute PageTo pageParam) throws Exception {
        return dictItemService.getDiceItemList( dictItem, pageParam);
    }


    /**
     * 获取 一条   二级字典
     *
     * @param dictItem
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/get", method = RequestMethod.POST)
    public DictItem getDictItem(@ModelAttribute DictItem dictItem) throws Exception {
        return  dictItemService.getDiceItemFromCache(dictItem);
    }

    /**
     * 新增字典
     *
     * @param dictItem 字典信息
     * @throws Exception
     */
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    public void saveDictItem(@ModelAttribute DictItem dictItem) throws Exception {
        dictItemService.saveDiceItem(dictItem);
    }

    /**
     * 删除字典
     *
     * @param dictItem 字典
     * @throws Exception
     */
    @RequestMapping(value = "/remove", method = RequestMethod.POST)
    public void deleteDictItem(@ModelAttribute DictItem dictItem) throws Exception {
        dictItemService.deleteDiceItem(dictItem);
    }

    /**
     * 修改字典
     *
     * @param dictItem 字典信息
     * @throws Exception
     */
    @RequestMapping(value = "/modify", method = RequestMethod.POST)
    public void updateDictItem(@ModelAttribute DictItem dictItem) throws Exception {
        dictItemService.updateDiceItem(dictItem);
    }

    /**
     *禁用一个 二级 字典
     * @param dictItem
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/update",method = RequestMethod.POST)
    public  void modifyDictItem(@ModelAttribute DictItem dictItem) throws Exception{
        dictItemService.modifyDictItem(dictItem);
    }

    /**
     *  获取一个字典下拉框  二 级（子类）
     * @param dictItem
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/comboBox", method = RequestMethod.POST)
    public  List<DictItem> comboBox(@ModelAttribute DictItem dictItem) throws Exception{
        return  dictItemService.comboBox(dictItem);
    }


}
